package top.btcmarket.auth.config;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.filter.GenericFilterBean;
import org.springframework.web.servlet.HandlerMapping;

public class MyFilterSecurityInterceptor extends GenericFilterBean  {

	

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		
		HttpServletRequest httpRequest = (HttpServletRequest)request;
		
		String pattern = (String)
				httpRequest.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);  
	 
	 String method = httpRequest.getMethod();
	 
	 System.out.println("------doFilter,pattern+---------"+pattern+",method:"+method);
	 
	 Enumeration<String> attributeNames = httpRequest.getAttributeNames();
		while (attributeNames.hasMoreElements()) {
			System.out.println(" ---doFilter--attributeNames------"+attributeNames.nextElement());
		}
		
		
		
		  RequestAttributes ra = RequestContextHolder.getRequestAttributes();
	        ServletRequestAttributes sra = (ServletRequestAttributes) ra;
	        HttpServletRequest request1 = sra.getRequest();
	        
	        String pattern1 = (String)
			        request1.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);  
		 
		 String method1 = request1.getMethod();
		 
		 System.out.println("Interceptor,init ,pattern+---------"+pattern1+",method:"+method1);
		
		
	}

	
}
